//
//  TTDianpuDomainViewController.m
//  TaoTuo
//
//  Created by admin on 2019/11/11.
//  Copyright © 2019 admin. All rights reserved.
//

#import "TTDianpuDomainViewController.h"

@interface TTDianpuDomainViewController ()

@property (nonatomic, copy) NSString *domain;
@property (nonatomic, copy) FinishedBlock finishBlock;
@property (nonatomic, strong) UITextField *textField;

@end

@implementation TTDianpuDomainViewController

- (instancetype)initWithDomain:(NSString *)domain finishBlock:(FinishedBlock)finishBlock
{
    self = [super init];
    if (self) {
        self.domain = domain ? : @"";
        self.finishBlock = finishBlock;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"绑定域名";
    
    UIButton *saveBtn = [UIButton createButtonWithTitle:@"完成" titleColor:kMainColor titleFont:[UIFont systemFontOfSize:15] backgroundColor:nil target:self action:@selector(completeAction)];
    saveBtn.frame = CGRectMake(0, 0, 40, 44);
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:saveBtn];
    
    [self setupSubViews];
}

// 点击完成
- (void)completeAction
{
    if (self.finishBlock) {
        self.finishBlock(self.textField.text);
    }
    [self.navigationController popViewControllerAnimated:YES];
}

//- (void)backAction
//{
//    LLSystemAlertView *alertView = [LLSystemAlertView alertViewWithTitle:@"提示" message:@"如不保存，填写的信息将会丢失" cancelTitle:@"取消" cancelBlock:^{
//        [self.navigationController popViewControllerAnimated:YES];
//    } confirmTitle:@"保存" confirmBlock:^BOOL{
//        [self completeAction];
//        return YES;
//    }];
//    [TYShowAlertView showAlertViewWithView:alertView backgoundTapDismissEnable:YES];
//}

- (void)setupSubViews
{
    UILabel *topLabel = [UILabel labelWithTitle:@"请输入域名" color:UIColorHex(333333) fontSize:11];
    [self.view addSubview:topLabel];
    [topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_topLayoutGuideBottom).mas_offset(15);
        make.left.mas_equalTo(15);
    }];
    
    _textField = [[UITextField alloc] init];
    _textField.placeholder = @"请输入域名（域名必须备案）";
    _textField.font = [UIFont systemFontOfSize:15];
    _textField.textColor = UIColorHex(333333);
    _textField.text = self.domain;
    _textField.keyboardType = UIKeyboardTypeASCIICapable;
    [self.view addSubview:_textField];
    [_textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(topLabel);
        make.top.equalTo(topLabel.mas_bottom);
        make.height.mas_equalTo(42);
        make.right.equalTo(self.view).mas_offset(-10);
    }];
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = UIColorHex(F0F4F7);
    [self.view addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.textField.mas_bottom);
        make.left.right.equalTo(self.textField);
        make.height.mas_equalTo(1);
    }];
    
    NSString *str = @"帮助：\n1、请将域名通过A记录解析到192.168.1.1；\n2、绑定完成后，即可通过该域名访问商城；\n3、设置的域名需IPC备案。";
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    style.lineSpacing = 5;
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:str];
    [attr addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:13], NSForegroundColorAttributeName : UIColorHex(666666)} range:[str rangeOfString:@"帮助："]];
    [attr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, str.length)];
    
    UILabel *bottomLabel = [UILabel labelWithTitle:@"" color:UIColorHex(999999) fontSize:11];
    bottomLabel.numberOfLines = 0;
    bottomLabel.attributedText = attr;
    [self.view addSubview:bottomLabel];
    [bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(lineView.mas_bottom).mas_offset(20);
        make.left.mas_equalTo(lineView);
        make.right.equalTo(self.view).mas_offset(-10);
    }];
    
}


@end
